
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>如何处理 Nginx 中的反向代理和负载均衡的请求头和请求体？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>如何处理 Nginx 中的反向代理和负载均衡的请求头和请求体？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Nginx中，用于设置或修改传递给后端服务器请求头的主要指令是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">用于设置或修改传递给后端服务器请求头的指令是 `proxy_set_header`。</div>
          </div>
          <div class="card-source">来源: 1.1. 转发请求头</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">在配置Nginx反向代理时，为了让后端服务器获取客户端的真实IP地址和请求协议，通常会设置哪四个关键的请求头？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">通常会设置四个关键的请求头：1. `Host` (转发原始请求的主机名)；2. `X-Real-IP` (客户端的真实IP地址)；3. `X-Forwarded-For` (客户端IP地址链)；4. `X-Forwarded-Proto` (请求使用的协议，如HTTP或HTTPS)。</div>
          </div>
          <div class="card-source">来源: 1.1. 转发请求头</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当Nginx作为反向代理处理一个POST请求时，它对请求体（request body）的默认处理方式是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">默认情况下，Nginx不会对请求体进行处理或修改，而是将客户端请求的请求体直接转发给后端服务器。</div>
          </div>
          <div class="card-source">来源: 2.1. 处理 POST 请求的请求体</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">如何通过Nginx配置来限制客户端请求体的最大允许大小，以防止过大的请求体导致服务问题？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">可以使用 `client_max_body_size` 指令来设置请求体的最大大小。例如，`client_max_body_size 10m;` 会将最大请求体限制为10MB。</div>
          </div>
          <div class="card-source">来源: 2.2. 配置请求体大小限制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">在Nginx中配置对WebSocket连接的反向代理时，必须设置哪两个特殊的请求头以确保协议能够成功升级？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">为了处理WebSocket连接，必须特别配置 `Upgrade` 和 `Connection` 这两个头部，以确保WebSocket协议能够成功升级。</div>
          </div>
          <div class="card-source">来源: 4.1. 配置 WebSocket 请求头</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在Nginx反向代理配置中，`X-Forwarded-For` 请求头的作用是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`X-Forwarded-For` 是一个记录客户端IP地址链的请求头，它记录了请求所经过的每一个代理服务器的IP地址。</div>
          </div>
          <div class="card-source">来源: 1.1. 转发请求头</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
